package com.wedo.mall.widget;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.wedo.mall.R;

/**
 * 店铺星级控件
 * Created by e on 2017/7/9.
 */

public class StarView extends LinearLayout {

    public StarView(Context context) {
        this(context,null);
    }

    public StarView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }

    public StarView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        star(4);
    }

    public void star(int star){
        setOrientation(HORIZONTAL);
        removeAllViews();
        for (int i= 0;i<star;i++){
            createStar();
        }
    }

    private void createStar(){
        ImageView iv = new ImageView(getContext());

        LayoutParams params = new LayoutParams(60,60);
        params.leftMargin = -13;
        params.rightMargin = -13;
        iv.setLayoutParams(params);
        iv.setScaleType(ImageView.ScaleType.FIT_XY);
        iv.setImageResource(R.drawable.home_dj_xx);
        this.addView(iv);
    }
}
